package com.cheboohui.iqs.taiping.direct.e;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.taiping.direct.DirectTp;
import com.cheboohui.iqs.taiping.direct.PublicNew;
import com.cheboohui.iqs.taiping.direct.RequestHead;
import com.cheboohui.iqs.taiping.direct.ResTaiPing;

/**
 * E06-订单详细信息查询
 * 
 * @author xielonghai
 * @version 2016-07-07
 */
public class E06Request {

	/**
	 * 用于用户报价后，且调用了“V03-确认保存”接口后，可根据生成的订单号可查询订单当前的状态及投保的产品险种信息;
	 * 需在支付前调用该接口并将订单详细信息展示给客户
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param orderNo
	 *            订单号
	 * @return
	 */
	public static ResTaiPing requestE06(String session, String orderNo) {
		String value = Config.value + ":辅助接口--根据订单号:" + orderNo + ",获取订单详情";

		String[] key = { "vehicle" // 车辆信息（vehicle）
				, "risk"// 险种信息（risk）--条数：一条或多条
				, "carOwner"// 车主信息（carOwner）
				, "applicant"// 投保人信息（applicant）
				, "insured"// 被保险人信息（insured）
				, "dispatch"// 配送信息（dispatch）
				, "itemKindBZ"// 交强险险别信息（itemKindBZ）
				, "itemKindBS"// 商业险险别信息（itemKindBS）---条数：一条或多条
				, "tax"// 车船税信息（tax）---若是投保了交强险，存在该节点信息
		};

		return DirectTp.request(value, PublicNew.REQUEST_URL + "/orderList", getRequest(session, orderNo), key);
	}

	/**
	 * 获取--E06-订单详细信息查询------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param orderNo
	 *            订单号
	 * @return
	 */
	private static String getRequest(String session, String orderNo) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		request = request + "\n\t" + "<clientName>" + head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<sales>";
		request = request + "\n\t\t" + "<groupNo>" + "chebaohui" + "</groupNo>";// 团队号
		request = request + "\n\t" + "</sales>";

		request = request + "\n\t" + "<order>";
		request = request + "\n\t\t" + "<orderNo>" + orderNo + "</orderNo>";// 订单号
		request = request + "\n\t" + "</order>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
